class CreateBasicSchema < ActiveRecord::Migration
  def self.up
    create_table :petrinets do |t|
      t.column :name, :string
      t.column :pid, :string #id from pnml
    end
    
    create_table :transitions do |t|
      t.string :type
      t.column :refer_type, :string
      t.column :refer_to, :string
      t.column :send_to_locator, :string#for dynamic/ "beam" urls
      t.column :send_to, :string #for static urls
      t.column :redirect_to_locator, :string#where to place redirect url in token xml
      t.column :redirect_to_transition, :string #to which transition redirect url should be set
      t.column :location_locator, :string#where to place location url got back from receive transition
      t.column :name, :string
      t.column :guard, :string
      t.column :role, :string
      t.column :petrinet_id, :integer
      t.column :xslt_url, :string
      t.column :output_model, :text
      t.column :output_form, :text
      t.column :output_bindings, :text
      t.column :pid, :string #id from pnml
      t.column :afterdeploy, :boolean, :default => true
      t.column :action, :string
      t.column :has_incoming_places, :boolean, :default => true
      t.column :has_inhibitor, :boolean, :default => true
    end    
    
    create_table :places do |t|
      #type for single table inheritance
      t.column :type, :string
      
      t.column :name, :string
      t.column :pid, :string #id from pnml
      t.column :petrinet_id, :integer
    end
    
    create_table :locators do |t|
      t.column :place_id, :integer
      t.column :name, :string
      t.column :expr, :string
      t.column :val_type, :string
    end
  
    create_table :tokens do |t|
      t.column :place_id, :integer
      t.column :value, :text
      #isn't needed? t.column :values, :text
      t.column :uuid, :string
      t.column :case_id, :integer
      t.column :is_active, :boolean, :default => true
    end

    create_table :arcs do |t|
      #type for single table inheritance
      t.column :type, :string
      t.column :from_is_place, :boolean
      t.column :petrinet_id, :integer
      t.column :transition_id, :integer
      t.column :place_id, :integer
      t.column :xslt_url, :string
      t.integer :weight, :default => 1, :null => false
      t.string :weight_xpath
      t.column :pid, :string #id from pnml
      t.column :case_transformation, :integer #see PNEngine::Arc
    end
    
    create_table :cases do |t|
      t.column :name, :string
      t.column :parent_id, :integer
    end
  end
  
  def self.down
    drop_table :petrinets
    drop_table :tokens
    drop_table :locators
    drop_table :transitions
    drop_table :places
    drop_table :arcs
    drop_table :cases
  end
end
